


import $$ from 'jquery'
export default {
  wechatShare(shareDate) {
    return new Promise(function(resolve, reject) {
      $$.ajax({
        url: 'http://www.iplan-ad.com/api/auth/index/share',//后台索要的算法签名
        type: 'POST',
        dataType: 'json',
        data: {
          url: window.location.href.split('#')[0],
        },
      }).done(function(ret) {
        wx.config({
          debug: false,
          appId: ret.appid, 
          timestamp:ret.timestamp, 
          nonceStr:ret.nonceStr,
          signature:ret.signature,
          jsApiList: [
            'onMenuShareAppMessage', //微信好友
            'onMenuShareTimeline', //朋友圈
            'onMenuShareQQ', //qq好友
            'onMenuShareWeibo', //微博
            'onMenuShareQZone', //qq空间
          ],
        })
        let share  = {
          title:'118易点达',
          desc: '让每个商家多赚点',
          link: 'http://www.iplan-ad.com/app/#/bomNav',
          // link: 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxfefc1188cb991ef1&redirect_uri=http%3a%2f%2fwww.iplan-ad.com%2fapp%2f%23%2fbomNav&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect',
          imgUrl: 'http://www.iplan-ad.com/static/images/weixin_20180327110113.jpg',
        }
        wx.ready(function () {
          wx.onMenuShareAppMessage({
            title:share.title,
            desc: share.desc,
            link: share.link,
            imgUrl: share.imgUrl,
            type: '', // 分享类型,music、video或link，不填默认为link            
            dataUrl: '',
            success:() =>{
              alert('分享好友成功')
            },
            cancel: ()=>{
              alert('分享好友失败，你取消了分享')
            },
          })
          wx.onMenuShareTimeline({
            title:share.title,
            desc: share.desc,
            imgUrl: share.imgUrl,
            success: function () {
              alert('分享朋友圈成功')
            },
            cancel: ()=>{
              alert('分享好友失败，你取消了分享')
            },
          })
          wx.onMenuShareQQ({
            title:share.title,
            desc: share.desc,
            link: share.link,
            imgUrl: share.imgUrl,
            success:() =>{
              alert('分享QQ好友成功')
            },
            cancel: ()=>{
              alert('分享QQ好友失败，你取消了分享')
            },
          });
          wx.onMenuShareWeibo({
            title:share.title,
            desc: share.desc,
            link: share.link,
            imgUrl: share.imgUrl,
            success:() =>{
              alert('分享微博成功')
            },
            cancel: ()=>{
              alert('分享失败')
            },
          });
          wx.onMenuShareQZone({
            title:share.title,
            desc: share.desc,
            link: share.link,
            imgUrl: share.imgUrl,
            success:() =>{
              alert('分享QQ空间成功')
            },
            cancel: ()=>{
              alert('分享失败')
            },
          });
        })
      }).fail(function(ret) {
        reject( ret );
      })
    })
  }
}